package com.hotel.user.mapper;

import com.hotel.common.utils.DBTools;
import org.springframework.stereotype.Repository;

import java.time.LocalDateTime;

@Repository
public class RolePermissionMapper {

    public int insert(Long roleId, Long permissionId) {
        String sql = "INSERT INTO role_permission (role_id, permission_id, created_at) VALUES (?, ?, ?)";
        return DBTools.update(sql, roleId, permissionId, LocalDateTime.now());
    }

    public int deleteByRoleIdAndPermissionId(Long roleId, Long permissionId) {
        String sql = "DELETE FROM role_permission WHERE role_id = ? AND permission_id = ?";
        return DBTools.update(sql, roleId, permissionId);
    }

    public int deleteByRoleId(Long roleId) {
        String sql = "DELETE FROM role_permission WHERE role_id = ?";
        return DBTools.update(sql, roleId);
    }

    public int deleteByPermissionId(Long permissionId) {
        String sql = "DELETE FROM role_permission WHERE permission_id = ?";
        return DBTools.update(sql, permissionId);
    }
}